#include "opengl_debug.h"
#include "opengl.h"
#include <iostream>

using namespace krryn::system;

void gl_call_manager::call_made(const char *a_FunctionName){
	m_LastCall = a_FunctionName;
}

void gl_call_manager::call_ended(){
	GLenum l_Error = glGetError();
	if(l_Error != GL_NO_ERROR){
		std::string l_Str;

		switch(l_Error){
			case GL_INVALID_ENUM: l_Str = "GL_INVALID_ENUM"; break;
			case GL_INVALID_VALUE: l_Str = "GL_INVALID_VALUE"; break;
			case GL_INVALID_OPERATION: l_Str = "GL_INVALID_OPERATION"; break;
			case GL_STACK_OVERFLOW: l_Str = "GL_STACK_OVERFLOW"; break;
			case GL_STACK_UNDERFLOW: l_Str = "GL_STACK_UNDERFLOW"; break;
			case GL_OUT_OF_MEMORY: l_Str = "GL_OUT_OF_MEMORY"; break;
			case GL_TABLE_TOO_LARGE: l_Str = "GL_TABLE_TOO_LARGE"; break;
			default: l_Str = "Unidentified error message"; break;
		}

		std::cout << "OpenGL error: " << l_Str << " in " << m_LastCall << std::endl;
	}
}

gl_call_manager &gl_call_manager::get_instance(){
	static gl_call_manager *i = 0;
	if(!i) i = new gl_call_manager();
	return *i;
}
